package com.health.fragment.person;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import com.health.viewscontrols.NovaApplication;
import com.health.viewscontrols.PersonalFileActivity;
import com.health.viewscontrols.PersonalFileActivity.onFragmentFresh;
import com.health.viewscontrols.PersonalFileActivity.onFragmentSave;
import com.health.R;
import com.health.db.FDbManager;
import com.health.model.PeopleType;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.BD_DD_INFO;
import com.health.tools.DateUtil;
import com.health.tools.GlobalConts;
import com.health.tools.JBRQData;
import com.health.tools.SPUtil;
import com.health.view.spinner.NiceSpinner;
import com.nova.BaseFragment;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

/***
 * 个人档案--详细信息
 * 
 * @author Administrator
 *
 */
public class DetailInfoFragment extends BaseFragment
		implements OnClickListener, OnCheckedChangeListener, onFragmentSave, onFragmentFresh {

	private static final String TAG = "DetailInfoFragment";
	private View view;
	/**
	 * 户主姓名
	 */
	private EditText nameEt;
	/**
	 * 户主编号
	 */
	// private EditText numberEt;
	// private EditText relationshipEt;
	private EditText departmentEt;
	private static EditText phoneEt;
	private EditText contectNameEt;
	private EditText contectPhoneEt;
	private EditText medicalHistoryEt;
	private EditText payEt;
	private EditText guominshiEt;
	private EditText bingcanEt;
	private EditText mailEt;
	private TextView idTv;
	private TextView dateTv;
	private TextView nameTv;
	private TextView detail_sex_tv;
	private TextView nationTv;
	private RadioGroup addrTypeRg;
	private RadioGroup bloodTypeRg;
	private RadioGroup yichuanbingTypeRg;
	private List<CheckBox> payChecks = new ArrayList<CheckBox>();
	private List<CheckBox> guominChecks = new ArrayList<CheckBox>();
	private List<CheckBox> baoluChecks = new ArrayList<CheckBox>();
	private List<CheckBox> canjiChecks = new ArrayList<CheckBox>();
	private List<CheckBox> peopleGroupChecks = new ArrayList<CheckBox>();
	private NiceSpinner relationshipSp;
	private NiceSpinner bloodTypeSp;
	private NiceSpinner marrySp;
	private NiceSpinner culturelevelSp;
	private NiceSpinner detail_youfu_sp;//是否优抚
	private NiceSpinner detail_pinkun_sp;//是否贫困
	private List<BD_DD_INFO> relaList;
	private List<BD_DD_INFO> marrayList;
	private List<BD_DD_INFO> wenhuaList;
	private List<BD_DD_INFO> bloodList;
	private ARCHIVE_BASEINFO userInfo;
	private EditText addrEt;
	private NiceSpinner jobSp;
	private List<BD_DD_INFO> jobList;
	private FDbManager fdbmanger = NovaApplication.fdbmanger;
	private String strWhere = "IDCARD LIKE '" + NovaApplication.getUserInfo().getIDCARD() + "'";
	private CheckBox people1;
	private CheckBox people2;
	private CheckBox people3;
	private CheckBox people4;
	private CheckBox people5;
	private CheckBox people6;
	private CheckBox people7;
	private CheckBox people8;
	private CheckBox people9;
	private CheckBox people10;
	private CheckBox people11;
	private CheckBox people12;
	private CheckBox people13;
	private CheckBox people14;
	private CheckBox people15;
	private int age;
	private LinearLayout linear_sfycf;
	private CheckBox check_isycf;
	CheckBox canji8;
	CheckBox canji1;
	CheckBox canji2;
	CheckBox canji3;
	CheckBox canji4;
	CheckBox canji5;
	CheckBox canji6;
	CheckBox canji7;
	CheckBox pay6;
	CheckBox pay7;
	private EditText householderNameEt;
	private EditText householderCardEt;
	private EditText familyNumEt;
	private EditText familyStructureEt;
	private RadioGroup liveSituationRg;

	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		userInfo = NovaApplication.getUserInfo();
		view = inflater.inflate(R.layout.detail_info, container, false);
		Log.e(TAG, "onCreateView()" + userInfo.getPOPULATION_TYPE());
		initView();
		setData();
		return view;
	}

	@Override
	public void onStart() {
		super.onStart();
		// initView();
	}

	@Override
	public void onResume() {
		super.onResume();
		Log.e(TAG, " onResume（）");
		// setData();
	}

	private void initView() {
		nameEt = (EditText) view.findViewById(R.id.detail_name_edit);
		// numberEt = (EditText) view.findViewById(R.id.detail_number_edit);
		// relationshipEt = (EditText)
		// view.findViewById(R.id.detail_relationship_edit);
		departmentEt = (EditText) view.findViewById(R.id.detail_department_edit);
		phoneEt = (EditText) view.findViewById(R.id.detail_phone_edit);
		contectNameEt = (EditText) view.findViewById(R.id.detail_contectname_edit);
		contectPhoneEt = (EditText) view.findViewById(R.id.detail_contectphone_edit);
		medicalHistoryEt = (EditText) view.findViewById(R.id.detail_medicalhistory_edit);
		payEt = (EditText) view.findViewById(R.id.detail_pay_edit);
		guominshiEt = (EditText) view.findViewById(R.id.detail_guominshi_edit);
		bingcanEt = (EditText) view.findViewById(R.id.detail_bingcan_edit);
		mailEt = (EditText) view.findViewById(R.id.detail_mail_edit);
		addrEt = (EditText) view.findViewById(R.id.detail_addr_edit);

		linear_sfycf = (LinearLayout) view.findViewById(R.id.linear_sfycf);
		check_isycf = (CheckBox) view.findViewById(R.id.check_isycf);
		check_isycf.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				System.out.println("qqqqqqqqqq" + isChecked);
			}
		});
		GlobalConts.setMaxLength(250, addrEt);// 户籍地址
		GlobalConts.setMaxLength(35, departmentEt);// 工作单位
		GlobalConts.setMaxLength(20, phoneEt);// 本人电话
		GlobalConts.setMaxLength(25, contectNameEt);// 联系人姓名
		GlobalConts.setMaxLength(11, contectPhoneEt);// 联系人电话
		GlobalConts.setMaxLength(100, mailEt);// 邮箱

		// GlobalConts.setMaxLength(100, nameEt);//支付方式其他
		// GlobalConts.setMaxLength(100, nameEt);//药物过敏史其他
		// GlobalConts.setMaxLength(100, nameEt);//残疾情况其他
		// GlobalConts.setMaxLength(100, nameEt);//

		idTv = (TextView) view.findViewById(R.id.detail_id_tv);
		dateTv = (TextView) view.findViewById(R.id.detail_date_tv);
		nameTv = (TextView) view.findViewById(R.id.detail_name_text);
		nationTv = (TextView) view.findViewById(R.id.detail_nation_text);

		addrTypeRg = (RadioGroup) view.findViewById(R.id.detail_addr_rg);
		bloodTypeRg = (RadioGroup) view.findViewById(R.id.detail_bloodtype_rg);
		yichuanbingTypeRg = (RadioGroup) view.findViewById(R.id.detail_yichanbing_rg);
		detail_sex_tv = (TextView) view.findViewById(R.id.detail_sex_tv);
		RadioButton yichuanHaveBtn = (RadioButton) view.findViewById(R.id.detail_yichuanbingyes);
		RadioButton yichuanNoBtn = (RadioButton) view.findViewById(R.id.detail_yichuanbingno);
		yichuanHaveBtn.setOnCheckedChangeListener(this);
		yichuanNoBtn.setOnCheckedChangeListener(this);

		relationshipSp = (NiceSpinner) view.findViewById(R.id.detail_relationship_sp);
		bloodTypeSp = (NiceSpinner) view.findViewById(R.id.detail_bloodtype_sp);
		marrySp = (NiceSpinner) view.findViewById(R.id.detail_marry_sp);
		culturelevelSp = (NiceSpinner) view.findViewById(R.id.culturelevel_sp);
		jobSp = (NiceSpinner) view.findViewById(R.id.detail_job_sp);
		detail_youfu_sp=view.findViewById(R.id.detail_youfu_sp);
		detail_pinkun_sp=view.findViewById(R.id.detail_pinkun_sp);
		payChecks = new ArrayList<CheckBox>();
		CheckBox pay1 = (CheckBox) view.findViewById(R.id.detail_pay1_ch);
		CheckBox pay2 = (CheckBox) view.findViewById(R.id.detail_pay2_ch);
		CheckBox pay3 = (CheckBox) view.findViewById(R.id.detail_pay3_ch);
		CheckBox pay4 = (CheckBox) view.findViewById(R.id.detail_pay4_ch);
		CheckBox pay5 = (CheckBox) view.findViewById(R.id.detail_pay5_ch);
		pay6 = (CheckBox) view.findViewById(R.id.detail_pay6_ch);
		pay7 = (CheckBox) view.findViewById(R.id.detail_pay7_ch);
		CheckBox pay8 = (CheckBox) view.findViewById(R.id.detail_pay8_ch);
		pay8.setOnCheckedChangeListener(this);
		payChecks.add(pay1);
		payChecks.add(pay2);
		payChecks.add(pay3);
		payChecks.add(pay4);
		payChecks.add(pay5);
		payChecks.add(pay6);
		payChecks.add(pay7);
		payChecks.add(pay8);

		guominChecks = new ArrayList<CheckBox>();
		CheckBox guomin0 = (CheckBox) view.findViewById(R.id.detail_guomin0_ch);
		CheckBox guomin1 = (CheckBox) view.findViewById(R.id.detail_guomin1_ch);
		CheckBox guomin2 = (CheckBox) view.findViewById(R.id.detail_guomin2_ch);
		CheckBox guomin3 = (CheckBox) view.findViewById(R.id.detail_guomin3_ch);
		CheckBox guomin4 = (CheckBox) view.findViewById(R.id.detail_guomin4_ch);
		guomin0.setOnCheckedChangeListener(this);
		guomin4.setOnCheckedChangeListener(this);
		guominChecks.add(guomin0);
		guominChecks.add(guomin1);
		guominChecks.add(guomin2);
		guominChecks.add(guomin3);
		guominChecks.add(guomin4);

		baoluChecks = new ArrayList<CheckBox>();

		CheckBox baolu1 = (CheckBox) view.findViewById(R.id.detail_baolu1_ch);
		CheckBox baolu2 = (CheckBox) view.findViewById(R.id.detail_baolu2_ch);
		CheckBox baolu3 = (CheckBox) view.findViewById(R.id.detail_baolu3_ch);
		CheckBox baolu4 = (CheckBox) view.findViewById(R.id.detail_baolu4_ch);
		baoluChecks.add(baolu1);
		baoluChecks.add(baolu2);
		baoluChecks.add(baolu3);
		baoluChecks.add(baolu4);
		baolu1.setOnCheckedChangeListener(this);

		canjiChecks = new ArrayList<CheckBox>();
		canji1 = (CheckBox) view.findViewById(R.id.detail_canji1_ch);
		canji2 = (CheckBox) view.findViewById(R.id.detail_canji2_ch);
		canji3 = (CheckBox) view.findViewById(R.id.detail_canji3_ch);
		canji4 = (CheckBox) view.findViewById(R.id.detail_canji4_ch);
		canji5 = (CheckBox) view.findViewById(R.id.detail_canji5_ch);
		canji6 = (CheckBox) view.findViewById(R.id.detail_canji6_ch);
		canji7 = (CheckBox) view.findViewById(R.id.detail_canji7_ch);
		canji8 = (CheckBox) view.findViewById(R.id.detail_canji8_ch);
		canji1.setOnCheckedChangeListener(this);
		canji8.setOnCheckedChangeListener(this);
		canjiChecks.add(canji1);
		canjiChecks.add(canji2);
		canjiChecks.add(canji3);
		canjiChecks.add(canji4);
		canjiChecks.add(canji5);
		canjiChecks.add(canji6);
		canjiChecks.add(canji7);
		canjiChecks.add(canji8);

		peopleGroupChecks = new ArrayList<CheckBox>();
		people1 = (CheckBox) view.findViewById(R.id.detail_peoplegroup1_ch);
		people2 = (CheckBox) view.findViewById(R.id.detail_peoplegroup2_ch);
		people3 = (CheckBox) view.findViewById(R.id.detail_peoplegroup3_ch);
		people4 = (CheckBox) view.findViewById(R.id.detail_peoplegroup4_ch);
		people5 = (CheckBox) view.findViewById(R.id.detail_peoplegroup5_ch);
		people6 = (CheckBox) view.findViewById(R.id.detail_peoplegroup6_ch);
		people7 = (CheckBox) view.findViewById(R.id.detail_peoplegroup7_ch);
		people8 = (CheckBox) view.findViewById(R.id.detail_peoplegroup8_ch);
		people9 = (CheckBox) view.findViewById(R.id.detail_peoplegroup9_ch);
		people10 = (CheckBox) view.findViewById(R.id.detail_peoplegroup10_ch);
		people11 = (CheckBox) view.findViewById(R.id.detail_peoplegroup11_ch);
		people12 = (CheckBox) view.findViewById(R.id.detail_peoplegroup12_ch);
		people13 = (CheckBox) view.findViewById(R.id.detail_peoplegroup13_ch);
		people14 = (CheckBox) view.findViewById(R.id.detail_peoplegroup14_ch);
		people15 = (CheckBox) view.findViewById(R.id.detail_peoplegroup15_ch);

		peopleGroupChecks.add(people1);
		peopleGroupChecks.add(people2);
		peopleGroupChecks.add(people3);
		peopleGroupChecks.add(people4);
		peopleGroupChecks.add(people5);
		peopleGroupChecks.add(people6);
		peopleGroupChecks.add(people7);
		peopleGroupChecks.add(people8);
		peopleGroupChecks.add(people9);
		peopleGroupChecks.add(people10);
		peopleGroupChecks.add(people11);
		peopleGroupChecks.add(people12);
		peopleGroupChecks.add(people13);
		peopleGroupChecks.add(people14);
		peopleGroupChecks.add(people15);

		//20250106补充字段
		householderNameEt = (EditText) view.findViewById(R.id.detail_householdername_edit);
		householderCardEt = (EditText) view.findViewById(R.id.detail_householdercard_edit);
		familyNumEt = (EditText) view.findViewById(R.id.detail_familyNum_edit);
		familyStructureEt = (EditText) view.findViewById(R.id.detail_familyStructure_edit);
		liveSituationRg = (RadioGroup) view.findViewById(R.id.detail_liveSituation_rg);
		for (CheckBox cb : peopleGroupChecks) {
			cb.setOnCheckedChangeListener(this);
		}

		payHuChi();
	}

	/**
	 *支付互斥
	 */
	private void payHuChi() {
		pay6.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					pay7.setEnabled(false);
				} else {
					pay7.setEnabled(true);
				}

			}
		});

		pay7.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					pay6.setEnabled(false);
				} else {
					pay6.setEnabled(true);
				}

			}
		});
	}

	@SuppressLint("SimpleDateFormat")
	public void setData() {
		userInfo = NovaApplication.getUserInfo();
		age = DateUtil.getAge(userInfo.getBIRTHDAY());
		nameTv.setText(userInfo.getCUSTOMERNAME());

		List<BD_DD_INFO> bdxingbie = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM01-08'");
		String sex = "";
		for (BD_DD_INFO bdi : bdxingbie) {
			if (userInfo.getSEX().equals(bdi.getID())) {
				sex = bdi.getDATAINFO();
			}
		}

		detail_sex_tv.setText(sex);

		setISycfVisible(sex);

		idTv.setText(userInfo.getIDCARD());
		nationTv.setText(userInfo.getMINORITY());
		Date birthday = userInfo.getBIRTHDAY();
		phoneEt.setText(userInfo.getPHONE());

		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		dateTv.setText(format.format(birthday));

		relaList = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, "parentid = 'DM01-06'", "cast(SORT as int) asc");
		ArrayList<String> list = new ArrayList<String>();
		for (BD_DD_INFO info : relaList) {
			list.add(info.getDATAINFO());
		}
		relationshipSp.attachDataSource(list);
		marrayList = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, "PARENTID = 'DM01-05'",
				"cast(SORT as int) asc");
		ArrayList<String> marryList = new ArrayList<String>();
		for (BD_DD_INFO info : marrayList) {
			marryList.add(info.getDATAINFO());
		}
		marrySp.attachDataSource(marryList);

		wenhuaList = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, "PARENTID = 'DM01-02'",
				"cast(SORT as int) asc");
		ArrayList<String> wenhuas = new ArrayList<String>();
		for (BD_DD_INFO info : wenhuaList) {
			wenhuas.add(info.getDATAINFO());
		}
		culturelevelSp.attachDataSource(wenhuas);
//是否优抚
		ArrayList<String> youfus = new ArrayList<String>();
		youfus.add("否");
		youfus.add("是");
		detail_youfu_sp.attachDataSource(youfus);
		//是否贫困
		ArrayList<String> pinkuns = new ArrayList<String>();
		pinkuns.add("否");
		pinkuns.add("是");
		detail_pinkun_sp.attachDataSource(youfus);

		bloodList = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, "PARENTID = 'DM01-12'", "cast(SORT as int) asc");
		ArrayList<String> bloods = new ArrayList<String>();
		for (BD_DD_INFO info : bloodList) {
			bloods.add(info.getDATAINFO());
		}
		bloodTypeSp.attachDataSource(bloods);

		jobList = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, "PARENTID = 'DM01-14'", "cast(SORT as int) asc");
		ArrayList<String> jobs = new ArrayList<String>();
		for (BD_DD_INFO info : jobList) {
			// (多出来的) DM01-14_X 军人 DM01-14_Y 不便分类的其他从业人员
			if (info.getID().equals("DM01-14_X") || info.getID().equals("DM01-14_Y")) {
			} else {
				jobs.add(info.getDATAINFO());
			}
		}
		jobSp.attachDataSource(jobs);
		addrEt.setText(userInfo.getHOUSEHOLD_ADDR());
		departmentEt.setText(userInfo.getWORKUNIT());
		if (userInfo.getRH() != null) {
			// DM01-13_1 1 否
			// DM01-13_2 2 是
			// DM01-13_3 3 不详
			// TODO
			// if (userInfo.getRH().equals("DM01-13_2")) {
			// bloodTypeRg.check(R.id.detail_rh);
			// } else if (userInfo.getRH().equals("DM01-13_1")) {
			// bloodTypeRg.check(R.id.detail_rhno);
			// } else if (userInfo.getRH().equals("DM01-13_3")) {
			// bloodTypeRg.check(R.id.detail_rhunknow);
			// }
			if (userInfo.getRH()
					.equals(fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
							"DATAINFO LIKE" + "'" + "阴性" + "'" + " AND PARENTID='DM01-13'", "cast(SORT as int)asc")
							.get(0).getID())) {
				bloodTypeRg.check(R.id.detail_rh);
			} else if (userInfo.getRH()
					.equals(fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
							"DATAINFO LIKE" + "'" + "阳性" + "'" + " AND PARENTID='DM01-13'", "cast(SORT as int)asc")
							.get(0).getID())) {
				bloodTypeRg.check(R.id.detail_rhno);
			} else if (userInfo.getRH()
					.equals(fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
							"DATAINFO LIKE" + "'" + "不详" + "'" + " AND PARENTID='DM01-13'", "cast(SORT as int)asc")
							.get(0).getID())) {
				bloodTypeRg.check(R.id.detail_rhunknow);
			}
		}
		contectNameEt.setText(userInfo.getCONTACTNAME());
		contectPhoneEt.setText(userInfo.getCONTACTPHONE());
		householderNameEt.setText(userInfo.getHOUSE_RELATION());
		householderCardEt.setText(userInfo.getHOUSE_REAL_OTHER());
		familyNumEt.setText(userInfo.getRES0());
		familyStructureEt.setText(userInfo.getRES1());
		if (userInfo.getRES2() != null) {
			// TODO
			 if (userInfo.getRES2().equals("live_Situation_1")) {
			 liveSituationRg.check(R.id.live_Situation_1);
			 } else if (userInfo.getRES2().equals("live_Situation_2")) {
				 liveSituationRg.check(R.id.live_Situation_2);
			}else if (userInfo.getRES2().equals("live_Situation_3")) {
				 liveSituationRg.check(R.id.live_Situation_3);
			}else if (userInfo.getRES2().equals("live_Situation_4")) {
				 liveSituationRg.check(R.id.live_Situation_4);
			}else if (userInfo.getRES2().equals("live_Situation_5")) {
				 liveSituationRg.check(R.id.live_Situation_5);
			}else if (userInfo.getRES2().equals("live_Situation_6")) {
				 liveSituationRg.check(R.id.live_Situation_6);
			}
		}
		mailEt.setText(userInfo.getEMAIL());
		if (userInfo.getLIVETYPE() != null) {

			if (userInfo.getLIVETYPE().equals("DM01-09_1")) {
				addrTypeRg.check(R.id.detail_huiji);

			} else if (userInfo.getLIVETYPE().equals("DM01-09_2")) {
				addrTypeRg.check(R.id.detail_feihuji);
			}
		}
		if (userInfo.getDISEASE() != null) {
			if (userInfo.getDISEASE().equals(fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,

					"DATAINFO LIKE" + "'" + "有" + "'" + " AND PARENTID='DM01-11'", "cast(SORT as int) asc").get(0)
					.getID())) {
				yichuanbingTypeRg.check(R.id.detail_yichuanbingyes);

			} else if (userInfo.getDISEASE()
					.equals(fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
							"DATAINFO LIKE" + "'" + "无" + "'" + " AND PARENTID='DM01-11'", "cast(SORT as int) asc")
							.get(0).getID())) {
				yichuanbingTypeRg.check(R.id.detail_yichuanbingno);
			}

		}

		String bloodCode = userInfo.getBLOODTYPE();
		List<BD_DD_INFO> bloodInfos = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
				"ID LIKE " + "'" + bloodCode + "'");
		if (bloodInfos.size() > 0) {

			String datainfo = bloodInfos.get(0).getDATAINFO();
			int indexOf = bloods.indexOf(datainfo);
			bloodTypeSp.setSelectedIndex(indexOf);
		}

		String cultureCode = userInfo.getCULTURE();
		List<BD_DD_INFO> cultureInfos = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
				"ID LIKE " + "'" + cultureCode + "'");
		if (cultureInfos.size() > 0) {
			int indexOf = wenhuas.indexOf(cultureInfos.get(0).getDATAINFO());
			culturelevelSp.setSelectedIndex(indexOf);

		}
		String youfuCode=userInfo.getISMATERIALS();
		if("DM01-10_1".equals(youfuCode)){
			detail_youfu_sp.setSelectedIndex(0);
		}else if("DM01-10_2".equals(youfuCode)){
			detail_youfu_sp.setSelectedIndex(1);
		}
		String pinkunCode=userInfo.getISPROVERTY();
		if("DM01-10_1".equals(pinkunCode)){
			detail_pinkun_sp.setSelectedIndex(0);
		}else if("DM01-10_2".equals(pinkunCode)){
			detail_pinkun_sp.setSelectedIndex(1);
		}

		String jobCode = userInfo.getJOB();
		List<BD_DD_INFO> jobInfos = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
				"ID LIKE " + "'" + jobCode + "'");
		if (jobInfos.size() > 0) {
			int indexOf = jobs.indexOf(jobInfos.get(0).getDATAINFO());
			jobSp.setSelectedIndex(indexOf);

		}

		String marryCode = userInfo.getMARITALSTATUS();
		List<BD_DD_INFO> marryInfos = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
				"ID LIKE " + "'" + marryCode + "'");
		if (marryInfos.size() > 0) {
			int indexOf = marryList.indexOf(marryInfos.get(0).getDATAINFO());
			marrySp.setSelectedIndex(indexOf);
		}

		setCheckStr(userInfo.getMEDICALPAYTYPE(), payChecks);
		NovaApplication.dbManger.addColumnByBySQL("ARCHIVE_BASEINFO", "YWGMS");
		Log.e(TAG, "userInfo.getPILLALLERGIC():" + userInfo.getPILLALLERGIC());
		if("DM01-11_1".equals(userInfo.getYWGMS())){
			guominChecks.get(0).setChecked(true);
		}else{
			guominChecks.get(0).setChecked(false);
		}
		setCheckStr(userInfo.getPILLALLERGIC(), guominChecks);
		setCheckStr(userInfo.getEXPOSURE(), baoluChecks);
		if (TextUtils.isEmpty(userInfo.getDISEASENDITION())) {
			canji1.setChecked(true);
		} else {
			setCheckStr(userInfo.getDISEASENDITION(), canjiChecks);
		}
		medicalHistoryEt.setText(userInfo.getDISEASE_EX());
		payEt.setText(userInfo.getMEDICALPAYTYPE_OTHER());
		guominshiEt.setText(userInfo.getPILLALLERGIC_OTHER());
		bingcanEt.setText(userInfo.getDISEASENDITION_EX());

		String pop = "";
		Log.e(TAG, "setData()" + userInfo.getPOPULATION_TYPE());
		if (!TextUtils.isEmpty(userInfo.getPOPULATION_TYPE())) {
			pop = userInfo.getPOPULATION_TYPE();
			String[] pops = pop.split(",");
			// /** 1:一般人群，2：儿童，3：孕产妇，4：老年人，5：重精神病，6：高血压，7：糖尿病，8：冠心病，9：脑卒中默认值1 */
			// for (CheckBox cb : peopleGroupChecks) {
			// cb.setChecked(false);
			// }
			// PeopleType.setPopleType(pops, peopleGroupChecks);

			if (Arrays.asList(pops).contains(PeopleType.WOMAN)) {
				// 设置孕产妇框
				check_isycf.setChecked(true);
			}

		}

	}

	public void save() {
		boolean flag = false;
		for (int i = 0, size = canjiChecks.size(); i < size; i++) {
			if (canjiChecks.get(i).isChecked()) {
				flag = true;
			}
		}

		if (!flag) {
			((PersonalFileActivity) getActivity()).showTextDialog("请选择残疾情况");
			return;
		}

		// String name = nameEt.getText().toString().trim();
		// String number = numberEt.getText().toString().trim();
		// String relationship = relationshipEt.getText().toString().trim();
		String addr = addrEt.getText().toString().trim();
		String department = departmentEt.getText().toString().trim();
		String phone = phoneEt.getText().toString().trim();

		String connectName = contectNameEt.getText().toString().trim();
		String connectPhone = contectPhoneEt.getText().toString().trim();
		String householderName = householderNameEt.getText().toString().trim();
		String householderCard = householderCardEt.getText().toString().trim();
		String familyNum = familyNumEt.getText().toString().trim();
		String familyStructure = familyStructureEt.getText().toString().trim();


		if (TextUtils.isEmpty(phone) && TextUtils.isEmpty(connectPhone)) {
			phoneEt.setBackgroundColor(Color.YELLOW);
			contectPhoneEt.setBackgroundColor(Color.YELLOW);
			((PersonalFileActivity) getActivity()).showTextDialog("本人电话与联系人电话至少填写一项");
			return;
		} else {
			phoneEt.setBackgroundColor(Color.WHITE);
			contectPhoneEt.setBackgroundColor(Color.WHITE);
		}

		// 户籍id
		int addrId = addrTypeRg.getCheckedRadioButtonId();

		if (addrId != -1) {
			String addrType = (String) ((RadioButton) (view.findViewById(addrId))).getText().toString();
			if (!TextUtils.isEmpty(addrType)) {
				addrTypeRg.setBackgroundColor(Color.WHITE);
				userInfo.setLIVETYPE(
						fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, "DATAINFO LIKE" + "'" + addrType + "'")
								.get(0).getID());
			} else {
				addrTypeRg.setBackgroundColor(Color.YELLOW);
				((PersonalFileActivity) getActivity()).showTextDialog("请选择一个常住类型");
				return;
			}

		} else {
			addrTypeRg.setBackgroundColor(Color.YELLOW);
			((PersonalFileActivity) getActivity()).showTextDialog("请选择一个常住类型");
			return;
		}
		// 文化程度
		int cultureIndex = culturelevelSp.getSelectedIndex();
		BD_DD_INFO cultureInfo = wenhuaList.get(cultureIndex);
		if (TextUtils.isEmpty(cultureInfo.getID())) {
			culturelevelSp.setBackgroundColor(Color.YELLOW);
			((PersonalFileActivity) getActivity()).showTextDialog("请选择文化程度");
			return;
		} else {
			userInfo.setCULTURE(cultureInfo.getID());
			culturelevelSp.setBackgroundColor(Color.WHITE);
		}
		//是否优抚
		int youfuIndex=detail_youfu_sp.getSelectedIndex();
		if(youfuIndex==0){
			userInfo.setISMATERIALS("DM01-10_1");
		}else if(youfuIndex==1){
			userInfo.setISMATERIALS("DM01-10_2");
		}
		//是否贫困
		int pinkunIndex=detail_pinkun_sp.getSelectedIndex();
		if(pinkunIndex==0){
			userInfo.setISPROVERTY("DM01-10_1");
		}else if(pinkunIndex==1){
			userInfo.setISPROVERTY("DM01-10_2");
		}
		// 职业
		int jobIndex = jobSp.getSelectedIndex();
		BD_DD_INFO jobInfo = jobList.get(jobIndex);
		userInfo.setJOB(jobInfo.getID());
		if (TextUtils.isEmpty(jobInfo.getID())) {
			jobSp.setBackgroundColor(Color.YELLOW);
			((PersonalFileActivity) getActivity()).showTextDialog("请选择职业");
			return;
		} else {
			userInfo.setJOB(jobInfo.getID());
			jobSp.setBackgroundColor(Color.WHITE);
		}

		// 婚姻状况
		int marryIndex = marrySp.getSelectedIndex();
		BD_DD_INFO marryInfo = marrayList.get(marryIndex);

		if (TextUtils.isEmpty(marryInfo.getID())) {
			marrySp.setBackgroundColor(Color.YELLOW);
			((PersonalFileActivity) getActivity()).showTextDialog("请选择婚姻状况");
			return;
		} else {
			userInfo.setMARITALSTATUS(marryInfo.getID());
			marrySp.setBackgroundColor(Color.WHITE);
		}

		String medicalHistory = medicalHistoryEt.getText().toString().trim();
		String payStr = payEt.getText().toString().trim();
		String guomin = guominshiEt.getText().toString().trim();

		String mail = mailEt.getText().toString().trim();

		// int relationIndex = relationshipSp.getSelectedIndex();
		int bloodTypeIndex = bloodTypeSp.getSelectedIndex();

		// BD_DD_INFO relationInfo = relaList.get(relationIndex);
		BD_DD_INFO bloodTypeInfo = bloodList.get(bloodTypeIndex);

		int bloodId = bloodTypeRg.getCheckedRadioButtonId();
		if (bloodId == -1) {
			bloodTypeRg.setBackgroundColor(Color.YELLOW);
			((PersonalFileActivity) getActivity()).showTextDialog("请选择RH");
			return;
		}

		int yichuanbingId = yichuanbingTypeRg.getCheckedRadioButtonId();

		String payType = getCheckStr(payChecks);
		String guominType = getCheckStr2(guominChecks, "DM02-10_1");
		Log.e(TAG, "guominType：" + guominType);
		String baoluType = getCheckStr2(baoluChecks, "DM01-15");
		String bingcan = bingcanEt.getText().toString().trim();
		if (canji8.isChecked()) {
			if (TextUtils.isEmpty(bingcan)) {
				bingcanEt.setBackgroundColor(Color.YELLOW);
				((PersonalFileActivity) getActivity()).showTextDialog("请输入其他残疾");
				return;
			}

		}

		String canjiType = getCheckStrCanJi(canjiChecks);
		// String peopleType = getCheckStr(peopleGroupChecks);

		// 遗传病史
		userInfo.setDISEASE_EX(medicalHistory);
		// 支付医疗费用
		userInfo.setMEDICALPAYTYPE_OTHER(payStr);

		// 病残其他
		userInfo.setDISEASENDITION_EX(bingcan);
		userInfo.setHOUSEHOLD_ADDR(addr);
		userInfo.setWORKUNIT(department);
		userInfo.setCONTACTNAME(connectName);
		userInfo.setCONTACTPHONE(connectPhone);
		userInfo.setEMAIL(mail);
		userInfo.setPHONE(phone);
		userInfo.setHOUSE_RELATION(householderName);
		userInfo.setHOUSE_REAL_OTHER(householderCard);
		userInfo.setRES0(familyNum);
		userInfo.setRES1(familyStructure);
		int liveSituationId = liveSituationRg.getCheckedRadioButtonId();
		if(liveSituationId != -1){
			String liveSituation = (String) ((RadioButton) (view.findViewById(liveSituationId))).getContentDescription().toString();
			userInfo.setRES2(liveSituation);
		}

		if (bloodId != -1) {
			String rh = (String) ((RadioButton) (view.findViewById(bloodId))).getText().toString();
			// TODO
			// DM01-13_1 1 否
			// DM01-13_2 2 是
			// DM01-13_3 3 不详

			userInfo.setRH(fdbmanger
					.findAllByWhereInInfoDB(BD_DD_INFO.class,
							"DATAINFO LIKE" + "'" + rh + "'" + " AND PARENTID='DM01-13'", "cast(SORT as int) asc")
					.get(0).getID());
			// userInfo.setRH(strBlood);
		}
		if (yichuanbingId != -1) {
			String yichuanbingText = (String) ((RadioButton) (view.findViewById(yichuanbingId))).getText().toString();
			if (!TextUtils.isEmpty(yichuanbingText)) {
				if (yichuanbingText.contains("有")) {
					yichuanbingText = "有";
				}
				userInfo.setDISEASE(fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
						"DATAINFO LIKE" + "'" + yichuanbingText + "'" + " AND PARENTID='DM01-11'",
						"cast(SORT as int) asc").get(0).getID());

			}

		}

		userInfo.setBLOODTYPE(bloodTypeInfo.getID());
		payType = payType.replaceAll("DM02-01_P_P9_P939", "DM02-08_99");
		userInfo.setMEDICALPAYTYPE(payType);
		if(!TextUtils.isEmpty(guominType)){
			userInfo.setYWGMS("DM01-11_2");

		}else{
			userInfo.setYWGMS("DM01-11_1");
		}
		userInfo.setPILLALLERGIC(guominType);

		// 过敏其他
		userInfo.setPILLALLERGIC_OTHER(guomin);
		userInfo.setEXPOSURE(baoluType);
		userInfo.setDISEASENDITION(canjiType);// 残疾情况
		try {
			userInfo.setLAST_UPDATE_DATE(
					GlobalConts.datetimeFormat.parse(GlobalConts.datetimeFormat.format(new Date())));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		getPop();
		// 有无残疾情况判断
		if (canji1.isChecked()) {
			// notCjr();
			clearGroup(PeopleType.CJR);
		} else {
			if (canji2.isChecked() || canji3.isChecked() || canji4.isChecked() || canji5.isChecked()
					|| canji6.isChecked() || canji7.isChecked() || canji8.isChecked()) {
				// isCjr();
				saveJBLX(PeopleType.CJR);
			}
		}

		// userInfo.setPOPULATION_TYPE(PeopleType.getPopleType(peopleGroupChecks));

		List<ARCHIVE_BASEINFO> infos = fdbmanger.findAllByWhere(ARCHIVE_BASEINFO.class, strWhere);
		if (infos.size() > 0) {
			// fdbmanger.delete(infos.get(0));
			fdbmanger.updata(userInfo, strWhere);
			userInfo.setUPDATEORG(SPUtil.getStrjddwno(getContext()));
		} else {
			fdbmanger.save(userInfo);
		}
		NovaApplication.setUserInfo(userInfo);

		showTextDialog("保存成功");
	}

	/**
	 * 清空疾病人群分类
	 * 
	 * @author 王婷婷
	 * @date 2017年9月22日 上午11:54:07
	 */
	private void clearGroup(String type) {
		JBRQData.clearGroup(type, userInfo);

		PersonalFileActivity activity = (PersonalFileActivity) getActivity();
		activity.freshDetailInfoData();
	}

	/**
	 * 保存疾病
	 * 
	 * @author 王婷婷
	 * @date 2017年9月22日 下午3:05:53
	 */
	private void saveJBLX(String peopleType) {
		JBRQData.saveJBLX(peopleType, userInfo);

		PersonalFileActivity activity = (PersonalFileActivity) getActivity();
		activity.freshDetailInfoData();
	}

	/**
	 * 
	 * 不是残疾人
	 * 
	 * @author 王婷婷
	 * @date 2017年12月16日 下午5:59:09
	 */
	private void notCjr() {
		String pop = userInfo.getPOPULATION_TYPE();
		if (TextUtils.isEmpty(pop)) {
			return;
		}

		if (!PeopleType.YBRQ.equals(pop)) {
			// 不是一般人群
			List<String> list = new ArrayList<String>();
			for (String t : pop.split(",")) {
				list.add(t);
			}
			if (list.contains(PeopleType.CJR)) {
				list.remove(PeopleType.CJR);
			}
			if (list.contains(PeopleType.YBRQ)) {
				list.remove(PeopleType.YBRQ);
			}
			String[] pops2 = list.toArray(new String[list.size()]);
			Log.e(TAG, "pops2()" + pops2.length);
			if (pops2.length == 0) {
				userInfo.setPOPULATION_TYPE(PeopleType.YBRQ);
			} else {
				pop = "";
				for (String s : pops2) {
					if (!TextUtils.isEmpty(s)) {
						if (TextUtils.isEmpty(pop)) {
							pop = s;
						} else {
							pop = pop + "," + s;
						}
					}
				}

				userInfo.setPOPULATION_TYPE(pop);
			}

		} else {
			userInfo.setPOPULATION_TYPE(PeopleType.YBRQ);
		}

		//
		// if (pop.contains(PeopleType.CJR)) {
		// List<String> list = new ArrayList<String>();
		// for (String t : pop.split(",")) {
		// list.add(t);
		// }
		// list.remove(PeopleType.CJR);
		// String peopleType = "";
		// for (int i = 0; i < list.size(); i++) {
		// if (list.size() == 1) {
		// peopleType = list.get(0);
		// } else {
		// peopleType = peopleType + "," + list.get(i);
		// }
		// }
		//
		// userInfo.setPOPULATION_TYPE(peopleType);
		// }
	}

	/**
	 * 是残疾人
	 * 
	 * @author 王婷婷
	 * @date 2017年12月16日 下午5:59:28
	 */
	private void isCjr() {
		if (TextUtils.isEmpty(userInfo.getPOPULATION_TYPE())) {
			userInfo.setPOPULATION_TYPE(PeopleType.CJR);
		} else {
			String pop = userInfo.getPOPULATION_TYPE();
			if (pop.contains(PeopleType.CJR)) {

			} else {
				List<String> list = new ArrayList<String>();
				for (String t : pop.split(",")) {
					list.add(t);
				}
				list.add(PeopleType.CJR);
				String peopleType = "";
				for (int i = 0; i < list.size(); i++) {
					if (list.size() == 1) {
						peopleType = list.get(0);
					} else {
						peopleType = peopleType + "," + list.get(i);
					}
				}

				userInfo.setPOPULATION_TYPE(peopleType);
			}
		}
	}

	private String getCheckStr(List<CheckBox> list) {
		String str = "";
		for (CheckBox box : list) {
			if (box.isChecked()) {
				String boxText = box.getText().toString();
				// ‘%[0-9]%’
				List<BD_DD_INFO> infos;
				if (boxText.contains("残疾")) {
					boxText = "%" + boxText;
				}
				infos = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, "DATAINFO LIKE" + " '" + boxText + "'",
						"cast(SORT as int) asc");
				if (infos.size() == 0) {
					return "";
				}
				BD_DD_INFO info = infos.get(infos.size() - 1);
				if (str.length() == 0) {
					str = info.getID();
				} else {
					str = str + "," + info.getID();
				}
			}
		}
		return str;
	}

	/**
	 * 获取残疾情况
	 */
	private String getCheckStrCanJi(List<CheckBox> list) {
		String str = "";
		String strr = "";
		for (int j = 0; j < list.size(); j++) {

			if (list.get(j).isChecked()) {
				// String boxText = list.get(j).getText().toString();

				List<BD_DD_INFO> infos;

				infos = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, "PARENTID='DM02-09'");
				if (infos.size() == 0) {
					return "";
				}

				if (str != null) {
					str += "," + infos.get(j).getID();
				} else {
					str = infos.get(j).getID() + "";
				}
			}
			if (str != null) {

				strr = str.replaceFirst(",", "");
			}
		}

		return strr;
	}

	/**
	 * 过敏
	 */
	private String getCheckStr2(List<CheckBox> list, String id) {
		String str = "";
		for (CheckBox box : list) {
			if (box.isChecked()) {
				String boxText = box.getText().toString();
				// ‘%[0-9]%’
				List<BD_DD_INFO> infos;
				if (boxText.contains("残疾")) {
					boxText = "%" + boxText;
				}
				infos = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
						"DATAINFO LIKE" + " '" + boxText + "'" + " AND PARENTID='" + id + "'", // TODO
						"cast(SORT as int) asc");
				if (infos.size() == 0) {

					return "";
				}
				BD_DD_INFO info = infos.get(infos.size() - 1);
				if (str.length() == 0) {
					str = info.getID();
				} else {
					str = str + "," + info.getID();
				}
			}
		}
		return str;
	}

	private void setCheckStr(String checkStr, List<CheckBox> checkList) {
		Log.e(TAG,"数据数据："+checkStr+"checkList:"+checkList);
		for(CheckBox cb:checkList){
			Log.e(TAG,"checkList:"+cb.getText().toString());
		}
		if (TextUtils.isEmpty(checkStr)) {
			return;
		}
		try {
			String[] strArr = checkStr.split(",");

			for (String str : strArr) {
				if(strArr.length == 0){
					return;
				}
				BD_DD_INFO checkInfo = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, "ID LIKE '" + str + "'").get(0);
				for (CheckBox box : checkList) {
					if (checkInfo.getDATAINFO().contains(box.getText().toString())) {
						box.setChecked(true);
					}
				}
			}
		}catch (Exception e){

		}
	}

	// private void setCheckStr2(String checkStr, List<CheckBox> checkList) {
	// if (TextUtils.isEmpty(checkStr)) {
	// return;
	// }
	// String[] strArr = checkStr.split(",");
	// for (String str : strArr) {
	// BD_DD_INFO checkInfo = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
	// "ID == '" + str + "'").get(0);
	// for (CheckBox box : checkList) {
	// if (checkInfo.getDATAINFO().contains(box.getText().toString())) {
	// box.setChecked(true);
	// }
	// }
	// }
	// }

	@Override
	public void onClick(View v) {

	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		int id = buttonView.getId();
		if (id == R.id.detail_pay8_ch) {
			// payEt.setFocusable(isChecked);
			payEt.setEnabled(isChecked);
			if (!isChecked) {
				payEt.setText("");
			}
		} else if (id == R.id.detail_guomin4_ch) {
			// guominshiEt.setFocusable(isChecked);
			guominshiEt.setEnabled(isChecked);
			if (!isChecked) {
				guominshiEt.setText("");
			}
		} else if (id == R.id.detail_guomin0_ch) {
			// 药物过敏史 无
			if (guominChecks.get(0).isChecked()) {
				for (int i = 1; i < guominChecks.size(); i++) {
					CheckBox cb = guominChecks.get(i);
					cb.setChecked(false);
					cb.setEnabled(false);
				}
			} else {
				for (int i = 1; i < guominChecks.size(); i++) {
					CheckBox cb = guominChecks.get(i);
					cb.setEnabled(true);
				}
			}
		} else if (id == R.id.detail_canji8_ch) {
			// bingcanEt.setFocusable(isChecked);
			bingcanEt.setEnabled(isChecked);
			if (!isChecked) {
				bingcanEt.setText("");
			}
		} else if (id == R.id.detail_yichuanbingyes) {
			// medicalHistoryEt.setFocusable(isChecked);
			medicalHistoryEt.setEnabled(isChecked);
			if (!isChecked) {
				medicalHistoryEt.setText("");
			}
		} else if (id == R.id.detail_yichuanbingno) {
			// medicalHistoryEt.setFocusable(!isChecked);
			medicalHistoryEt.setEnabled(!isChecked);
		} else if (id == R.id.detail_peoplegroup1_ch) {
			if (isChecked) {
				people2.setChecked(false);
				people3.setChecked(false);
				people4.setChecked(false);
				people5.setChecked(false);
				people6.setChecked(false);
				people7.setChecked(false);
				people8.setChecked(false);
				people9.setChecked(false);
				people10.setChecked(false);
				people11.setChecked(false);
				people12.setChecked(false);
				people13.setChecked(false);
				people14.setChecked(false);
				people15.setChecked(false);

				people2.setEnabled(false);
				people3.setEnabled(false);
				people4.setEnabled(false);
				people5.setEnabled(false);
				people6.setEnabled(false);
				people7.setEnabled(false);
				people8.setEnabled(false);
				people9.setEnabled(false);
				people10.setEnabled(false);
				people11.setEnabled(false);
				people12.setEnabled(false);
				people13.setEnabled(false);
				people14.setEnabled(false);
				people15.setEnabled(false);
			} else {
				people2.setEnabled(true);
				people3.setEnabled(true);
				people4.setEnabled(true);
				people5.setEnabled(true);
				people6.setEnabled(true);
				people7.setEnabled(true);
				people8.setEnabled(true);
				people9.setEnabled(true);
				people10.setEnabled(true);
				people11.setEnabled(true);
				people12.setEnabled(true);
				people13.setEnabled(true);
				people14.setEnabled(true);
				people15.setEnabled(true);
			}
		} else if (id == R.id.detail_peoplegroup2_ch) {
			if (isChecked) {
				if (age > 6) {
					// GlobalConts.showToast(getActivity(), "用户非儿童");
					showTextDialog("用户非儿童");
					buttonView.setChecked(false);
				}
			}
		} else if (id == R.id.detail_peoplegroup3_ch) {
			if (userInfo.getSEX().equals("DM01-08_1") || (age > 55) || (age < 14)) {
				// GlobalConts.showToast(getActivity(), "用户非孕妇");
				showTextDialog("用户非孕产妇");
				buttonView.setChecked(false);
			}
		} else if (id == R.id.detail_peoplegroup4_ch) {
			if (age < 65) {
				// GlobalConts.showToast(getActivity(), "用户非老年人");
				showTextDialog("用户非老年人");
				buttonView.setChecked(false);
			}
		} else if (id == R.id.detail_peoplegroup5_ch) {
		} else if (id == R.id.detail_baolu1_ch) {
			if (baoluChecks.get(0).isChecked()) {
				for (int i = 1; i < baoluChecks.size(); i++) {
					CheckBox cb = baoluChecks.get(i);
					cb.setChecked(false);
					cb.setEnabled(false);
				}
			} else {
				for (int i = 1; i < baoluChecks.size(); i++) {
					CheckBox cb = baoluChecks.get(i);
					cb.setEnabled(true);
				}
			}
		} else if (id == R.id.detail_canji1_ch) {
			if (isChecked) {
				for (int i = 1; i < canjiChecks.size(); i++) {
					CheckBox cb = canjiChecks.get(i);
					cb.setChecked(false);
					cb.setEnabled(false);
				}
			} else {
				for (int i = 1; i < canjiChecks.size(); i++) {
					CheckBox cb = canjiChecks.get(i);
					cb.setEnabled(true);
				}
			}
		} else if (id == R.id.detail_peoplegroup7_ch) {
		} else if (id == R.id.detail_peoplegroup8_ch) {
		} else if (id == R.id.detail_peoplegroup9_ch) {
		} else if (id == R.id.detail_peoplegroup10_ch) {
		} else {
		}

	}

	@Override
	public void setTizhong(String value) {

	}

	@Override
	public void setXuetang(String value) {

	}

	@Override
	public void setXueya(String gaoya, String diya, String mailv) {

	}

	@Override
	public void setTiWen(String tiwen) {

	}

	@Override
	public void setXueHongDanBai(String xhdb) {

	}

	@Override
	public void setMaiLv(String mailv) {

	}

	@Override
	public void setLiBangECG(String libangEcgResult, String time) {

	}

	@Override
	public void setNiaoYeFenxi(String niaoDanYuan, String qianXue, String DanHongSu, String tongti, String puTaoTang,
			String danBaiZhi, String PH, String yaXiaoSuan, String baiXiBao, String biZhong, String weiShengSu) {

	}

	@Override
	public void setCHOL(String dgc) {

	}

	@Override
	public void setXinLv(String xinlv) {
		// TODO Auto-generated method stub

	}

	@Override
	public void setXueYang(String xueYang) {

	}

	public static void setPhone(String phone) {
		phoneEt.setText(phone);
	}

	/**
	 * 设置孕妇选择框是否可见
	 * 
	 * @param sex
	 * @author 王婷婷
	 * @date 2017年9月22日 上午10:13:18
	 */
	private void setISycfVisible(String sex) {
		if ("女".equals(sex)) {
			check_isycf.setChecked(false);
			Log.e(TAG, "" + age);
			if (age >= 14 && age <= 55) {
				linear_sfycf.setVisibility(View.VISIBLE);
			} else {
				linear_sfycf.setVisibility(View.GONE);
			}

		} else {
			linear_sfycf.setVisibility(View.GONE);
			check_isycf.setChecked(false);
		}

	}

	/**
	 * 用户表中 --人群分类（用作 家庭签约医生）
	 * 
	 * @param idNo
	 * @author 王婷婷
	 * @date 2017年3月2日 下午2:42:35
	 */
	private void getPop() {

		String population = "";
		// 年龄判断
		if (age >= 14 && age <= 55 && check_isycf.isChecked()) {
			// 孕妇
			population = PeopleType.WOMAN;
			Log.e("yunfu", "yunfu");
		} else if ((age) >= 65) {
			// 老年人
			population = PeopleType.OLD;
		} else if (age <= 6) {
			// 儿童
			population = PeopleType.CHILD;
		}

		if (!TextUtils.isEmpty(userInfo.getPOPULATION_TYPE())) {
			Log.e(TAG, "getPop()" + userInfo.getPOPULATION_TYPE());

			// 不是一般人群
			String pop = userInfo.getPOPULATION_TYPE();
			List<String> list = new ArrayList<String>();
			for (String t : pop.split(",")) {
				list.add(t);
			}
			if (!check_isycf.isChecked()) {
				if (list.contains(PeopleType.WOMAN)) {
					list.remove(PeopleType.WOMAN);
				}
			}
			if (TextUtils.isEmpty(userInfo.getDISEASENDITION()) || "DM02-09_01".equals(userInfo.getDISEASENDITION())
					|| canji1.isChecked()) {
				// 无残疾
				if (list.contains(PeopleType.CJR)) {
					list.remove(PeopleType.CJR);
				}
			} else {
				if (!list.contains(PeopleType.CJR)) {
					list.add(PeopleType.CJR);
				}
			}

			if (!list.contains(population)) {
				list.add(population);
			}
			if (list.contains(PeopleType.YBRQ)) {
				list.remove(PeopleType.YBRQ);
			}
			String[] pops2 = list.toArray(new String[list.size()]);
			Log.e(TAG, "pops2()" + pops2.length);
			for (int i = 0; i < pops2.length; i++) {
				Log.e(TAG, "pops22()" + pops2[i]);
			}
			if (pops2.length == 0) {
				userInfo.setPOPULATION_TYPE(PeopleType.YBRQ);
			} else {
				pop = "";
				for (String s : pops2) {
					if (!TextUtils.isEmpty(s)) {
						if (TextUtils.isEmpty(pop)) {
							pop = s;
						} else {
							pop = pop + "," + s;
						}
					}

				}
				Log.e(TAG, "pop()" + pop);
				if (TextUtils.isEmpty(pop)) {
					userInfo.setPOPULATION_TYPE(PeopleType.YBRQ);
				} else {
					userInfo.setPOPULATION_TYPE(pop);
				}
			}

		} else {
			userInfo.setPOPULATION_TYPE(population);
		}
		Log.e(TAG, "getPop()" + userInfo.getPOPULATION_TYPE());
		NovaApplication.setUserInfo(userInfo);
		fdbmanger.updata(userInfo);
		PersonalFileActivity activity = (PersonalFileActivity) getActivity();
		activity.freshDetailInfoData();
	}
}
